package com.yunfangdata.web.controller;


import com.yunfangdata.domain.OtherCases;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IOtherCasesService;
import com.yunfangdata.util.JsonResult;
import com.yunfangdata.util.PageResult;
import com.yunfangdata.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("otherCases")
public class OtherCasesController {
    @Autowired
    private IOtherCasesService otherCasesService;

    @RequiresPermissions("otherCases:byStaffList")
    @PermissionName("其他情况列表")
    @RequestMapping("byStaffList")
    @ResponseBody
    public PageResult list(QueryObject qo) {
        return otherCasesService.query(qo);
    }

    @RequiresPermissions("otherCases:saveOrUpdate")
    @PermissionName("其他情况更新或保存")
    @RequestMapping("saveOrUpdate")
    @ResponseBody
    public JsonResult saveOrUpdate(OtherCases entity) {
        JsonResult jsonResult = new JsonResult();
        if (entity.getId() != null) {
            try {
                otherCasesService.update(entity);
            } catch (Exception e) {
                e.printStackTrace();
                jsonResult = new JsonResult("更新失败");
            }
        } else {
            try {
                otherCasesService.save(entity);
            } catch (Exception e) {
                e.printStackTrace();
                jsonResult = new JsonResult("保存失败");
            }
        }
        return jsonResult;
    }

    @RequiresPermissions("otherCases:delete")
    @PermissionName("其他情况删除")
    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult jsonResult = new JsonResult();
        if (id != null) {
            try {
                otherCasesService.delete(id);
            } catch (Exception e) {
                e.printStackTrace();
                jsonResult = new JsonResult("删除失败");
            }
        }
        return jsonResult;
    }
}
